package com.leyu.mall.site.home.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;

import com.leyu.mall.common.facade.ICmsChannelFacade;
import com.leyu.mall.common.facade.ICmsContentFacade;
import com.leyu.mall.common.facade.ICmsNewsFacade;
import com.leyu.mall.common.facade.ICmsSlideFacade;
import com.leyu.mall.common.facade.IGoodsBaseFacade;
import com.leyu.mall.site.sale.service.ISaleRankListService;
/**
 * 〈一句话功能简述〉 〈功能详细描述〉
 * 
 * @author OOKK
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@Scope(value = "prototype")
@RequestMapping("/")
public class SiteHomeController {

	@Autowired
	private ICmsNewsFacade cmsNewsFacade;
	
	@Autowired
	private ICmsChannelFacade cmsChannelFacade;

	@Autowired
	private ICmsContentFacade cmsContentFacade;
	
	@Resource(name = "saleRankListServiceImpl")
	private ISaleRankListService saleRankListFacade;
	
	@Autowired
	private ICmsSlideFacade cmsSlideFacade;
	@Autowired
	private IGoodsBaseFacade goodsBaseFacade;
	
	
	
 
	
//	@RequestMapping("/list")
//	public String list(Model model) {
//		try {
//			List channellist = cmsChannelFacade.getDisplayChannelList();
//			model.addAttribute("channellist", channellist);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		return "inc/list.html";
//	}
	@ExceptionHandler(Exception.class)
	public String exception(Exception e, HttpServletRequest request) {
		request.setAttribute("exception", e);
		return "/error.html";
	}

	@RequestMapping("/bottom")
	public String bottom(Model model) {
		return "/bottom.html";
	}
	@RequestMapping("/header")
	public String header(Model model) {
		return "/header.html";
	}
	@RequestMapping("/menu")
	public String menu(Model model) {
		return "/menu.html";
	}

	@RequestMapping("/index")
	public String index(Model model) {
		try {
			model.addAttribute("adlist", cmsContentFacade.getDisplayADList());
			model.addAttribute("ranklist", saleRankListFacade
					.getAllSaleRankList());
			model.addAttribute("list", cmsChannelFacade.getDisplayChannelList());
			model.addAttribute("newslist", cmsNewsFacade.getAllCmsNews());
			model.addAttribute("slidelist", cmsSlideFacade.getDisplaySlideList());
			model.addAttribute("newgoodslist", goodsBaseFacade.getNewGoodsList());
			model.addAttribute("hotgoodslist", goodsBaseFacade.getHotGoodsList());
			model.addAttribute("groupgoodslist", goodsBaseFacade.getGroupGoodsList());
			
//			cmsContentServiceImpl.getDisplayADtList();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "/index.html";
	}
}
